package nsq

import (
	sqlc "bp/db/sqlc"
	"context"
)

// UpsertNsqPub 新建/更新nsq_pub
func (s *NsqEntityServiceImp) UpsertNsqPub(ctx context.Context, q *sqlc.Queries, topic, sn string, messageBytes []byte) (err error) {
	err = q.UpsertNsqPub(ctx, sqlc.UpsertNsqPubParams{
		Topic:   topic,
		Sn:      sn,
		Message: messageBytes,
	})
	if err != nil {
		return
	}
	return
}

// MarkNsqPubSendSuccess 标记nsq消息已发送
func (s *NsqEntityServiceImp) MarkNsqPubSendSuccess(ctx context.Context, q *sqlc.Queries, id int64) (err error) {
	err = q.MarkNsqPubSendSuccess(ctx, id)
	if err != nil {
		return
	}
	return
}

// UpdateNsqPubError 更新nsq发送消息错误
func (s *NsqEntityServiceImp) UpdateNsqPubError(ctx context.Context, q *sqlc.Queries, id int64, errMsg string) (err error) {
	err = q.UpdateNsqPubError(ctx, sqlc.UpdateNsqPubErrorParams{
		ID:     id,
		ErrMsg: sqlc.NSFromString(errMsg),
	})
	if err != nil {
		return
	}
	return
}
